package com.yanqu.road.web.controller.usercenter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.dao.impl.admin.AdminCommonDaoImpl;
import com.yanqu.road.dao.impl.admin.AdminCommonDaoImpl2;
import com.yanqu.road.entity.admin.AdminInnerBuyOrderData;
import com.yanqu.road.entity.admin.AdminResult;
import com.yanqu.road.entity.admin.AdminResult2;
import com.yanqu.road.entity.enums.eChannelType;
import com.yanqu.road.entity.enums.ePlatformForbiddenType;
import com.yanqu.road.entity.enums.eServerState;
import com.yanqu.road.entity.player.InternalUserIpLocation;
import com.yanqu.road.entity.servercenter.AppIdChaneelInfo;
import com.yanqu.road.entity.servercenter.ChannelNotice;
import com.yanqu.road.entity.servercenter.ServerInfo;
import com.yanqu.road.entity.servercenter.tabnotice.ChannelTabNotice;
import com.yanqu.road.entity.servercenter.tabnotice.TabNotice;
import com.yanqu.road.logic.redis.RedisManger;
import com.yanqu.road.reids.subpub.eRedisChannelType;
import com.yanqu.road.server.manger.ChatControlMgr;
import com.yanqu.road.server.manger.ServerListMgr;
import com.yanqu.road.utils.config.Config;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.http.HttpHelper;
import com.yanqu.road.utils.string.StringUtils;
import com.yanqu.road.web.WebServer;
import com.yanqu.road.web.controller.usercenter.newadmin.CenterReloadHelper;
import com.yanqu.road.web.mgr.AdminMgr;
import com.yanqu.road.web.mgr.RegisterPlayerNumMgr;
import com.yanqu.road.web.mgr.RoleCreateCountMgr;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.concurrent.*;

@RestController
@RequestMapping("/usercenter/admin")
public class CenterAdminFrontController {

    /**
     * 心跳
     */
    @ResponseBody
    @RequestMapping("/heart")
    public String heart(){
        return String.valueOf(System.currentTimeMillis());
    }


    /**
     *  内服接口：1.6 内充购买项列表
     */
    @ResponseBody
    @RequestMapping(value = "playerCanBuyList", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String playerCanBuyList(HttpServletRequest request, @RequestBody String json){

        JSONObject jsonObject = JSONObject.parseObject(json);

        if(jsonObject.containsKey("serverId")){
            long serverId = jsonObject.getLongValue("serverId");
            ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
            if(serverInfo != null){
                String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/playerCanBuyList", json, "UTF-8");
                if(!StringUtils.isNullOrEmpty(response)){
                    return response;
                }
            }
        }

        AdminResult2 result = AdminResult2.failMsg("操作失败");

        return result.toJsonString();
    }

    /**
     * 内服接口：1.8 充值购买
     */
    @ResponseBody
    @RequestMapping(value = "playerBuy", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String playerBuy(HttpServletRequest request, @RequestBody String json){

        if(StringUtils.isNullOrEmpty(json)){
            return AdminResult.failMsg("请求参数空").toJsonString();
        }

        JSONObject paramObject = JSONObject.parseObject(json);

        String orderId = paramObject.getString("orderId");
        if(StringUtils.isNullOrEmpty(orderId)){
            return AdminResult.failMsg("orderId 参数空").toJsonString();
        }

        if(AdminMgr.getInnerBuyOrderDataMap().containsKey(orderId)){
            return AdminResult.defaultInstance().toJsonString();
        }

        if(paramObject.containsKey("serverId")){
            long serverId = paramObject.getLongValue("serverId");
            ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
            if(serverInfo != null){
                //拉长超时时间
                Map<String, String> response = HttpHelper.httpPostJson(serverInfo.getWebServerUrl() + "/game/admin/playerBuy", json, "UTF-8",
                        null, 30 * 1000, 30 * 1000, 30 * 1000);
                String code = response.getOrDefault("code", "0");
                if("200".equals(code)){
                    String body = response.get("body");
                    AdminResult2 temp = JSONObject.parseObject(body, AdminResult2.class);
                    if(temp != null){
                        if(temp.getCode() != -1){
                            //订单入库
                            AdminInnerBuyOrderData orderData = new AdminInnerBuyOrderData();
                            orderData.setOrderId(orderId);
                            orderData.setOrderTime(System.currentTimeMillis());
                            orderData.setInsertOption();
                            AdminMgr.getInnerBuyOrderDataMap().put(orderData.getOrderId(), orderData);
                        }
                    }
                    return body;
                }
            }
        }

        AdminResult result = AdminResult.defaultInstance();

        return result.toJsonString();
    }

    /**
     *  内服接口：1.1 角色检查
     */
    @ResponseBody
    @RequestMapping(value = "checkAccount", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String checkAccount(HttpServletRequest request, @RequestBody String json){



        JSONObject object = JSONObject.parseObject(json);

        if(!object.containsKey("playerList")){
            return AdminResult.failMsg("playerList 为空").toJsonString();
        }
        JSONArray playerList = object.getJSONArray("playerList");
        int size = playerList.size();
        Map<Long, List<Long>> userMap = new HashMap<>();
        for (int i = 0; i < size; i++) {
            JSONObject jsonObject = playerList.getJSONObject(i);
            Long serverId = jsonObject.getLong("serverId");
            Long userId = jsonObject.getLong("userId");
            if(serverId == null || userId == null){
                continue;
            }
            if(!userMap.containsKey(serverId)){
                userMap.put(serverId, new ArrayList<>());
            }
            userMap.get(serverId).add(userId);
        }

        Map<Long, String> callResult = new HashMap<>();
        for (Map.Entry<Long, List<Long>> entry : userMap.entrySet()) {
            long serverId = entry.getKey();
            String param = StringUtils.listToString(entry.getValue(), ",");
            ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
            if(serverInfo != null){
                Map<String, String> paramMap = new HashMap<>();
                paramMap.put("userId", param);
                String response = HttpHelper.doPost(serverInfo.getWebServerUrl() + "/game/admin/checkAccount", paramMap, "UTF-8");
                if(StringUtils.isNullOrEmpty(response)){

                }else {
                    callResult.put(serverId, response);
                }
            }
        }

        if(callResult.size() == 0) {
            return AdminResult.failMsg("失败").toJsonString();
        }

        AdminResult2 adminResult2 = AdminResult2.defaultInstance();

        for (Map.Entry<Long, String> entry : callResult.entrySet()) {
            long serverId = entry.getKey();
            JSONObject jo = JSON.parseObject(entry.getValue());
            JSONObject data = jo.getJSONObject("data");
            if(data != null && data.containsKey("userIdList")){
                adminResult2.setCode(-1);
                data.put("serverId", serverId);
                adminResult2.getData().add(data);
            }
        }

        return adminResult2.toJsonString();
    }

    /**
     * 内服接口：1.4 角色查询
     */
    @ResponseBody
    @RequestMapping(value = "roleSearch", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String roleSearch(HttpServletRequest request, @RequestBody String json){

        JSONObject paramObject = JSONObject.parseObject(json);
        JSONArray userServer = paramObject.getJSONArray("userServer");

        if(userServer == null || userServer.size() == 0){
            return AdminResult.failMsg("userServer 参数不存在").toJsonString();
        }

        int size = userServer.size();
        Map<Long, List<Long>> userMap = new HashMap<>();
        for (int i = 0; i < size; i++) {
            JSONObject jsonObject = userServer.getJSONObject(i);
            Long serverId = jsonObject.getLong("serverId");
            Long userId = jsonObject.getLong("userId");
            if(serverId == null || userId == null){
                continue;
            }
            if(!userMap.containsKey(serverId)){
                userMap.put(serverId, new ArrayList<>());
            }
            userMap.get(serverId).add(userId);
        }

        paramObject.remove(userServer);
        Map<Long, String> callResult = new HashMap<>();
        for (Map.Entry<Long, List<Long>> entry : userMap.entrySet()) {
            long serverId = entry.getKey();
            ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
            if(serverInfo != null){
                JSONObject reqObj = new JSONObject();
                reqObj.putAll(paramObject);
                reqObj.remove("userServer");
                String userIdList = StringUtils.listToString(entry.getValue(), ",");
                reqObj.put("userIdList", userIdList);
                String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/roleSearch", JSON.toJSONString(reqObj), "UTF-8");
                if(StringUtils.isNullOrEmpty(response)){

                }else {
                    callResult.put(serverId, response);
                }
            }
        }

        if(callResult.size() == 0) {
            return AdminResult.failMsg("失败").toJsonString();
        }

        AdminResult result = AdminResult.defaultInstance();
        JSONArray rows = new JSONArray();
        int total = 0;
        for (Map.Entry<Long, String> entry : callResult.entrySet()) {
            long serverId = entry.getKey();
            JSONObject jo = JSON.parseObject(entry.getValue());
            JSONObject data = jo.getJSONObject("data");
            if(data != null){
                total += data.getIntValue("total");
                JSONArray row = data.getJSONArray("row");
                rows.addAll(row);
            }
        }
        result.getData().put("total", total);
        result.getData().put("row", rows);

        return result.toJsonString();
    }

    /**
     * 内服接口：1.5 修改状态
     */
    @ResponseBody
    @RequestMapping(value = "forbiddenPlayer", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String forbiddenPlayer(HttpServletRequest request, @RequestBody String json){

        JSONObject paramObject = JSONObject.parseObject(json);

        int status = paramObject.getIntValue("status");

        String forbiddenEndTime = paramObject.getString("forbiddenEndTime");

        JSONArray jsonArray = paramObject.getJSONArray("rows");

        if(jsonArray == null){
            return AdminResult.failMsg("操作失败").toJsonString();
        }

        int size = jsonArray.size();
        Map<Long, List<Long>> userMap = new HashMap<>();
        for (int i = 0; i < size; i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            Long serverId = jsonObject.getLong("serverId");
            Long userId = jsonObject.getLong("userId");
            if(serverId == null || userId == null){
                continue;
            }
            if(!userMap.containsKey(serverId)){
                userMap.put(serverId, new ArrayList<>());
            }
            userMap.get(serverId).add(userId);
        }

        Map<Long, String> callResult = new HashMap<>();
        for (Map.Entry<Long, List<Long>> entry : userMap.entrySet()) {
            long serverId = entry.getKey();
            ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
            if(serverInfo != null && serverInfo.getState() == eServerState.Normal.getValue()){
                String userIdList = StringUtils.listToString(entry.getValue(), ",");
                JSONObject reqObj = new JSONObject();
                reqObj.put("status", status);
                reqObj.put("forbiddenEndTime", forbiddenEndTime);
                reqObj.put("userIdList", userIdList);
                String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/forbiddenPlayer", JSON.toJSONString(reqObj), "UTF-8");
                if(StringUtils.isNullOrEmpty(response)){

                }else {
                    callResult.put(serverId, response);
                }
            }else {
                ServerListMgr.getLogger().info("forbiddenPlayer server {} offline", serverId);
            }
        }

        if(callResult.size() == 0) {
            return AdminResult.failMsg("失败").toJsonString();
        }

        AdminResult result = AdminResult.defaultInstance();

        for (Map.Entry<Long, String> entry : callResult.entrySet()) {
            JSONObject jo = JSON.parseObject(entry.getValue());
            JSONObject data = jo.getJSONObject("data");
            if(data != null){
                result.getData().putAll(data);
            }
        }
        return result.toJsonString();
    }

    /**
     * 内服接口：1.7 内服用户修改定位
     */
    @ResponseBody
    @RequestMapping(value = "modifyLocation", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String modifyLocation(HttpServletRequest request, @RequestBody String json){

        JSONObject paramObject = JSONObject.parseObject(json);

        if(paramObject.containsKey("serverId")){
            long serverId = paramObject.getLongValue("serverId");

            int channelId = ServerListMgr.getChannelId(serverId);
            if(Config.isDebug() || eChannelType.isMainLandChannel(channelId)){
                long userId = paramObject.getLongValue("userId");
                String location = paramObject.getString("location");
                //国服
                boolean success = true;
                if("实际".equals(location)){
                    new AdminCommonDaoImpl2().deleteInternalUserIpLocation(userId);
                }else {
                    InternalUserIpLocation ipLocation = new AdminCommonDaoImpl2().getInternalUserIpLocation(userId);
                    if(ipLocation == null){
                        success = new AdminCommonDaoImpl2().addInternalUserIpLocation(userId, channelId, serverId, location);
                    }else {
                        success = new AdminCommonDaoImpl2().updateInternalUserIpLocation(userId, location);
                    }
                }
                if(!success){
                    return AdminResult.failMsg("操作失败").toJsonString();
                }
                ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
                if(serverInfo != null) {
                    CenterReloadHelper.serverMgrReload(Collections.singletonList(serverInfo), "WhiteListLocationMgr", 10);
                    return AdminResult.defaultInstance().toJsonString();
                }
            }else {
                //海外其他渠道，直接修改
                ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
                if (serverInfo != null && serverInfo.getState() == eServerState.Normal.getValue()) {
                    String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/modifyLocation", json, "UTF-8");
                    if (!StringUtils.isNullOrEmpty(response)) {
                        return response;
                    }
                }
            }
        }

        return AdminResult.failMsg("操作失败").toJsonString();
    }

    /**
     *  2.4 区服列表
     */
    @ResponseBody
    @RequestMapping(value = "channelServerList", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public String channelServerList(HttpServletRequest request, @RequestParam("channelId") int channelId, @RequestParam("appId") String appId){

        List<ServerInfo> serverList = ServerListMgr.getChannelServerList(channelId);

        AdminResult2 result2 = AdminResult2.defaultInstance();
        for (ServerInfo serverInfo : serverList) {
            JSONObject serverObj = new JSONObject();
            serverObj.put("serverId", serverInfo.getServerId());
            serverObj.put("serverName", serverInfo.getServerName());
            result2.getData().add(serverObj);
        }

        return result2.toJsonString();
    }

    /**
     *  2.5 区服APPID 下拉框查询
     */
    @ResponseBody
    @RequestMapping(value = "channelAppIdList", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String channelAppIdList(HttpServletRequest request, @RequestBody String json){

        JSONObject jsonObject = JSONObject.parseObject(json);

        JSONArray jsonArray = jsonObject.getJSONArray("channelIds");
        List<Integer> channelIds = new ArrayList<>();
        for (int i = 0; i < jsonArray.size(); i++) {
            channelIds.add(jsonArray.getIntValue(i));
        }

        List<AppIdChaneelInfo> list = new ArrayList<>();
        for (Map.Entry<String, AppIdChaneelInfo> entry : ServerListMgr.getAppIdChaneelInfoMap().entrySet()) {
            AppIdChaneelInfo channelInfo = entry.getValue();
            if(channelIds.contains(channelInfo.getChannelId())){
                list.add(channelInfo);
            }
        }

        AdminResult2 result2 = AdminResult2.defaultInstance();
        for (AppIdChaneelInfo appIdChaneelInfo : list) {
            JSONObject serverObj = new JSONObject();
            serverObj.put("appId", appIdChaneelInfo.getAppId());
            serverObj.put("appName", appIdChaneelInfo.getAppIdName());
            result2.getData().add(serverObj);
        }

        return result2.toJsonString();
    }

    /**
     * 2.6 重置头像
     */
    @ResponseBody
    @RequestMapping(value = "resetHeaderDecoration", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String resetHeaderDecoration(HttpServletRequest request, @RequestBody JSONObject json){

        long serverId = json.getLongValue("serverId");

        ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
        if(serverInfo == null){
            return AdminResult.failMsg("参数有误").toJsonString();
        }

        String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/resetHeaderDecoration", JSON.toJSONString(json), "UTF-8");
        if(StringUtils.isNullOrEmpty(response)){
            return AdminResult.failMsg("网络失败").toJsonString();
        }
        if(HttpHelper.ERROR.equals(response)){
            return AdminResult.failMsg("网络失败").toJsonString();
        }
        return response;
    }

    /**
     * 2.7 用户改名
     */
    @ResponseBody
    @RequestMapping(value = "changeUserNickName", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String changeUserNickName(HttpServletRequest request, @RequestBody JSONObject json){

        long serverId = json.getLongValue("serverId");

        ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
        if(serverInfo == null){
            return AdminResult.failMsg("参数有误").toJsonString();
        }

        String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/changeUserNickName", JSON.toJSONString(json), "UTF-8");
        if(StringUtils.isNullOrEmpty(response)){
            return AdminResult.failMsg("网络失败").toJsonString();
        }
        if(HttpHelper.ERROR.equals(response)){
            return AdminResult.failMsg("网络失败").toJsonString();
        }
        return response;
    }

    /**
     * 2.8 特殊封禁方式
     */
    @ResponseBody
    @RequestMapping(value = "specialForbiddenTypes", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public String specialForbiddenTypes(HttpServletRequest request){
        AdminResult result = AdminResult.defaultInstance();

        List<Map<String, Object>> dataList = new ArrayList<>();

        List<String> cmdList = StringUtils.stringToStringList("20908,通缉功能|22326,参加盛宴(自元宝)|22952,活动送财|22326,加入跨服宴会|22403,送财" +
                "|20112,修改昵称|20902,商战出战准备|20918,跨服商战出战|22110,修改商会信息|24351,酒肆|26032,厢房留言(他人)|26030,厢房留言(自己)|23304,弹幕", "\\|");
        for (String s : cmdList) {
            List<String> list = StringUtils.stringToStringList(s, ",");
            Map<String, Object> map = new HashMap<>();
            map.put("key", list.get(0));
            map.put("name", list.get(1));
            map.put("type", "cmd");
            dataList.add(map);
        }
        result.getData().put("list", dataList);
        return result.toJsonString();
    }

    /**
     * 2. 9解封详情
     */

    /**
     * 3.1 公告操作
     */

    @ResponseBody
    @RequestMapping(value = "channelNotice", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String channelNotice(HttpServletRequest request, @RequestBody String json){

        JSONObject jsObject = JSONObject.parseObject(json);

        int channelId = jsObject.getIntValue("channelId");
        String appId = jsObject.getString("appId");
        JSONArray list = jsObject.getJSONArray("list");

        if(eChannelType.forValue(channelId) == null){
            return AdminResult.failMsg("channelId 错误").toJsonString();
        }

        boolean success = false;

        if(eChannelType.isMainLandChannel(channelId)){
            //大陆，更新子渠道
            List<ChannelNotice> noticeList = new ArrayList<>();

            for (int i = 0; i < list.size(); i++) {
                JSONObject object = list.getJSONObject(i);
                ChannelNotice notice = new ChannelNotice();
                notice.setContent(object.getString("content"));
                notice.setTitle(object.getString("title"));
                notice.setLanguage(object.getString("language"));
                notice.setAppId(appId);
                noticeList.add(notice);
            }

            if(noticeList.size() > 0){
                success = new AdminCommonDaoImpl().batchUpdateChannelAppNotice(noticeList);
            }

        }else {
            //海外更新渠道
            List<ChannelNotice> noticeList = new ArrayList<>();

            int maxId = new AdminCommonDaoImpl().getChannelNoticeMaxId(channelId);

            for (int i = 0; i < list.size(); i++) {
                JSONObject object = list.getJSONObject(i);
                ChannelNotice notice = new ChannelNotice();
                notice.setId(maxId);
                notice.setContent(object.getString("content"));
                notice.setTitle(object.getString("title"));
                notice.setLanguage(object.getString("language"));
                notice.setChannelId(channelId);
                noticeList.add(notice);
            }

            if(noticeList.size() > 0){
                success = new AdminCommonDaoImpl().batchUpdateChannelNotice(noticeList);
            }

        }

        if(success){
            //重载
            String message = "ChannelNoticeMgr" + ";" + System.currentTimeMillis() / 1000;
            RedisManger.getRedisUtil().publish(eRedisChannelType.CenterManagerReload.getChannel(), eRedisChannelType.CenterManagerReload.getMessageKey(message));
        }

        if(!success){
            return AdminResult.failMsg("失败").toJsonString();
        }

        return AdminResult.defaultInstance().toJsonString();
    }

    /**
     * 3.1 公告操作  2.0
     */

    @ResponseBody
    @RequestMapping(value = "channelNotice20", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String channelNotice20(HttpServletRequest request, @RequestBody String json){

        JSONObject jsObject = JSONObject.parseObject(json);

        int channelId = jsObject.getIntValue("channelId");
        String appId = jsObject.getString("appId");
        JSONArray list = jsObject.getJSONArray("list");

        if(eChannelType.forValue(channelId) == null){
            return AdminResult.failMsg("channelId 错误").toJsonString();
        }

        boolean success = false;

        if(eChannelType.isMainLandChannel(channelId)){
            //大陆，更新子渠道
            List<ChannelNotice> noticeList = new ArrayList<>();

            for (int i = 0; i < list.size(); i++) {
                JSONObject object = list.getJSONObject(i);
                ChannelNotice notice = new ChannelNotice();
                notice.setContent(object.getString("content"));
                notice.setTitle(object.getString("title"));
                notice.setLanguage(object.getString("language"));
                notice.setAppId(appId);
                noticeList.add(notice);
            }

            if(noticeList.size() > 0){
                success = new AdminCommonDaoImpl().batchUpdateChannelAppNotice20(noticeList);
            }

        }else {

        }

        if(success){
            //重载
            String message = "ChannelNoticeMgr" + ";" + System.currentTimeMillis() / 1000;
            RedisManger.getRedisUtil().publish(eRedisChannelType.CenterManagerReload.getChannel(), eRedisChannelType.CenterManagerReload.getMessageKey(message));
        }

        if(!success){
            return AdminResult.failMsg("失败").toJsonString();
        }

        return AdminResult.defaultInstance().toJsonString();
    }

    /**
     * 2.1 角色查询
     */
    @ResponseBody
    @RequestMapping(value = "roleSearch2", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String roleSearch2(HttpServletRequest request, @RequestBody String json){

        JSONObject paramObject = JSONObject.parseObject(json);

        if(paramObject.containsKey("serverId")){
            long serverId = paramObject.getLongValue("serverId");
            ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
            if(serverInfo != null){
                String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/roleSearch2", json, "UTF-8");
                if(!StringUtils.isNullOrEmpty(response)){
                    return response;
                }
            }
        }

        return AdminResult.failMsg("操作失败").toJsonString();
    }


    /**
     * 2.2 角色状态修改
     */
    @ResponseBody
    @RequestMapping(value = "roleModify", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String roleModify(HttpServletRequest request, @RequestBody String json){

        JSONObject paramObject = JSONObject.parseObject(json);

        if(paramObject.containsKey("serverId")){
            long serverId = paramObject.getLongValue("serverId");
            ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
            if(serverInfo != null){
                String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/roleModify", json, "UTF-8");
                if(!StringUtils.isNullOrEmpty(response)){
                    return response;
                }
            }
        }

        return AdminResult.failMsg("操作失败").toJsonString();
    }

    /**
     * 2.3 角色强制下线
     */
    @ResponseBody
    @RequestMapping(value = "roleOffline", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String roleOffline(HttpServletRequest request, @RequestBody String json){

        JSONObject paramObject = JSONObject.parseObject(json);

        if(paramObject.containsKey("serverId")){
            long serverId = paramObject.getLongValue("serverId");
            ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
            if(serverInfo != null && serverInfo.getState() == eServerState.Normal.getValue()){
                String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/roleOffline", json, "UTF-8");
                if(!StringUtils.isNullOrEmpty(response)){
                    return response;
                }
            }
        }

        return AdminResult.failMsg("操作失败").toJsonString();
    }

    /**
     * 2.8 特殊封禁方式
     */
    @ResponseBody
    @RequestMapping(value = "getForbiddenType", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String getForbiddenType(HttpServletRequest request, @RequestBody String json) {
        AdminResult2 result = AdminResult2.defaultInstance();

        for (ePlatformForbiddenType type : ePlatformForbiddenType.values()) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("key", type.getName());
            jsonObject.put("name", type.getDesc());
            result.getData().add(jsonObject);
        }

        return result.toJsonString();
    }

    /**
     * 2.11 托管
     */
    @ResponseBody
    @RequestMapping(value = "role/trusteeship", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String roleTrusteeship(HttpServletRequest request, @RequestBody JSONObject jsonParam){

        if(!jsonParam.containsKey("serverId") || !jsonParam.containsKey("userId")){
            return AdminResult.failMsg("参数缺失").toJsonString();
        }
        long serverId = jsonParam.getLongValue("serverId");
        ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
        if(serverInfo == null){
            return AdminResult.failMsg("区服不存在").toJsonString();
        }

        String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/role/trusteeship", jsonParam.toJSONString(), "UTF-8");
        if(!StringUtils.isNullOrEmpty(response)){
            return response;
        }

        return AdminResult.failMsg("").toJsonString();
    }

    /**
     * 2.12 取消托管
     */
    @ResponseBody
    @RequestMapping(value = "role/cancelTrusteeship", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String roleCancelTrusteeship(HttpServletRequest request, @RequestBody JSONObject jsonParam){

        if(!jsonParam.containsKey("serverId") || !jsonParam.containsKey("userId")){
            return AdminResult.failMsg("参数缺失").toJsonString();
        }
        long serverId = jsonParam.getLongValue("serverId");
        ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
        if(serverInfo == null){
            return AdminResult.failMsg("区服不存在").toJsonString();
        }

        String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/role/cancelTrusteeship", jsonParam.toJSONString(), "UTF-8");
        if(!StringUtils.isNullOrEmpty(response)){
            return response;
        }

        return AdminResult.failMsg("").toJsonString();
    }

    /**
     * 2.13 角色详情
     */
    @ResponseBody
    @RequestMapping(value = "character/detail", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String characterDetail(HttpServletRequest request, @RequestBody JSONObject jsonParam){

        if(jsonParam.containsKey("serverId")){
            long serverId = jsonParam.getLongValue("serverId");
            ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
            if(serverInfo != null){
                String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/character/detail", jsonParam.toJSONString(), "UTF-8");
                if(!StringUtils.isNullOrEmpty(response)){
                    return response;
                }
            }
        }

        return AdminResult.failMsg("操作失败").toJsonString();
    }

    /**
     * 2.14 背包修改
     */
    @ResponseBody
    @RequestMapping(value = "role/packageChange", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String rolePackageChange(HttpServletRequest request, @RequestBody JSONObject jsonParam){

        if(!jsonParam.containsKey("serverId") || !jsonParam.containsKey("userId")){
            return AdminResult.failMsg("参数缺失").toJsonString();
        }
        long serverId = jsonParam.getLongValue("serverId");
        long userId = jsonParam.getLongValue("userId");
        int isAllowNegative = jsonParam.getIntValue("isAllowNegative");

        ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
        if(serverInfo == null){
            return AdminResult.failMsg("区服不存在").toJsonString();
        }

        String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/role/packageChange", jsonParam.toJSONString(), "UTF-8");
        if(!StringUtils.isNullOrEmpty(response)){
            return response;
        }

        return AdminResult.failMsg("").toJsonString();
    }

    /**
     * 2.18 封禁列表  获取角色封禁状态
     */
    @ResponseBody
    @RequestMapping(value = "getUserForbiddenStatus", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String getUserForbiddenStatus(HttpServletRequest request, @RequestBody String json){
        JSONObject paramObject = JSONObject.parseObject(json);
        if(paramObject.containsKey("serverId")){
            long serverId = paramObject.getLongValue("serverId");
            ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
            if(serverInfo != null){
                String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/getUserForbiddenStatus", json, "UTF-8");
                if(!StringUtils.isNullOrEmpty(response)){
                    return response;
                }
            } else {
                AdminResult.failMsg("服务器未找到").toJsonString();
            }
        }

        return AdminResult.failMsg("操作失败").toJsonString();
    }

    /**
     * 2.21 元宝修改 （2024.11.13 更新）
     */
    @ResponseBody
    @RequestMapping(value = "role/ingots/modify", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String ingotsModify(HttpServletRequest request, @RequestBody JSONObject jsonParam){

        if(!jsonParam.containsKey("serverId") || !jsonParam.containsKey("userId")){
            return AdminResult.failMsg("参数缺失").toJsonString();
        }

        int changeNum = jsonParam.getIntValue("changeNum");

        long serverId = jsonParam.getLongValue("serverId");
        ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
        if(serverInfo == null){
            return AdminResult.failMsg("区服不存在").toJsonString();
        }

        String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/role/ingots/modify", jsonParam.toJSONString(), "UTF-8");
        if(!StringUtils.isNullOrEmpty(response)){
            return response;
        }

        return AdminResult.failMsg("").toJsonString();
    }

    /**
     * 2.15 批量背包修改
     */
    @ResponseBody
    @RequestMapping(value = "role/packageChange2", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String rolePackageChange2(HttpServletRequest request, @RequestBody JSONObject jsonParam){

//        if(!jsonParam.containsKey("serverId") || !jsonParam.containsKey("userId")){
//            return AdminResult.failMsg("参数缺失").toJsonString();
//        }
        long isAllowNegative = jsonParam.getIntValue("isAllowNegative");

        JSONArray jsonArray = jsonParam.getJSONArray("batchPackageChangeDetailMapList");
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            long serverId = jsonObject.getLong("serverId");
            ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
            if(serverInfo == null){
                continue;
            }
            long userId = jsonObject.getLong("userId");
            String updateContent = jsonObject.getString("updateContent");
            JSONObject paramObj = new JSONObject();
            paramObj.put("isAllowNegative", isAllowNegative);
            paramObj.put("serverId", serverId);
            paramObj.put("userId", userId);
            paramObj.put("updateContent", updateContent);
            String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/role/packageChange2", paramObj.toJSONString(), "UTF-8");
            if(!StringUtils.isNullOrEmpty(response)){
                return response;
            }
        }

        return AdminResult.failMsg("").toJsonString();
    }

    /**
     * 2.19 vip经验修改
     */
    @ResponseBody
    @RequestMapping(value = "role/vip", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String vip(HttpServletRequest request, @RequestBody JSONObject jsonParam){
        long serverId = jsonParam.getIntValue("serverId");
        if(serverId <= 0){
            return AdminResult.failMsg("区服参数缺失").toJsonString();
        }

        ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);

        String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/role/vip", jsonParam.toJSONString(), "UTF-8");
        if (StringUtils.isNullOrEmpty(response)) {
            return AdminResult.failMsg("网络失败").toJsonString();
        }
        if (HttpHelper.ERROR.equals(response)) {
            return AdminResult.failMsg("网络失败").toJsonString();
        }

        return response;
    }

    /**
     * 2.24 修改头衔
     */
    @ResponseBody
    @RequestMapping(value = "role/titleChange", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String titleChange(HttpServletRequest request, @RequestBody JSONObject jsonParam){
        if(!jsonParam.containsKey("serverId") || !jsonParam.containsKey("userId")){
            return AdminResult.failMsg("参数缺失").toJsonString();
        }

        long serverId = jsonParam.getLongValue("serverId");
        ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
        if(serverInfo == null){
            return AdminResult.failMsg("区服不存在").toJsonString();
        }

        String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/role/titleChange", jsonParam.toJSONString(), "UTF-8");
        if(!StringUtils.isNullOrEmpty(response)){
            return response;
        }

        return AdminResult.failMsg("").toJsonString();
    }

    /**
     * 2.25 批量角色状态修改（封号/解封号，禁言/解禁言，托管/解托管，禁止修改名称/解禁修改名称，禁止修改头像/解禁修改头像）
     */
    @ResponseBody
    @RequestMapping(value = "roleModifyBatch", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String roleModifyBatch(HttpServletRequest request, @RequestBody String json){
        JSONObject paramObject = JSONObject.parseObject(json);

        JSONArray jsonArray = paramObject.getJSONArray("list");

        for (Object obj : jsonArray) {
            JSONObject jsonObject = (JSONObject) obj;
            if (jsonObject.containsKey("serverId")) {
                long serverId = jsonObject.getLongValue("serverId");
                paramObject.put("userIdList", jsonObject.getJSONArray("userIdList"));
                ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
                if (serverInfo != null) {
                    String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/roleModify", paramObject.toJSONString(), "UTF-8");
                    if (!StringUtils.isNullOrEmpty(response)) {
                        return response;
                    }
                }
                int channelId = ServerListMgr.getChannelId(serverId);
                ChatControlMgr.reloadChatControl(channelId);
            }
        }

        return AdminResult.failMsg("操作失败").toJsonString();
    }

    /**
     *  4.1 区服下拉框查询（包括未开服区服）
     */
    @ResponseBody
    @RequestMapping(value = "channelsServerList", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String channelsServerList(HttpServletRequest request, @RequestBody JSONObject jsonObject){

        if(!jsonObject.containsKey("channelIds")){
            return AdminResult.failMsg("channelIds 参数缺失").toJsonString();
        }

        AdminResult2 result2 = AdminResult2.defaultInstance();
        JSONArray jsonArray = jsonObject.getJSONArray("channelIds");
        for (int i = 0; i < jsonArray.size(); i++) {
            int channelId = jsonArray.getIntValue(i);

            List<ServerInfo> serverList = ServerListMgr.getChannelServerList(channelId);

            for (ServerInfo serverInfo : serverList) {
                JSONObject serverObj = new JSONObject();
                serverObj.put("serverId", serverInfo.getServerId());
                serverObj.put("serverName", serverInfo.getServerName());
                result2.getData().add(serverObj);
            }
        }

        return result2.toJsonString();
    }

    /**
     *  4.2 页签名称下拉框查询
     */
    @ResponseBody
    @RequestMapping(value = "getLabel", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public String getLabel(HttpServletRequest request, @RequestParam("channelId") int channelId){

        AdminResult2 result2 = AdminResult2.defaultInstance();
        List<ServerInfo> serverList = ServerListMgr.getChannelServerList(channelId);

        Set<String> set = new HashSet<>();
        for (ServerInfo serverInfo : serverList) {
            set.add(serverInfo.getMarkStr());
        }
        for (String s : set) {
            result2.getData().add(s);
        }
        return result2.toJsonString();
    }

    /**
     *  4.3 区服查询
     */
    @ResponseBody
    @RequestMapping(value = "serverDetailList", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String serverDetailList(HttpServletRequest request, @RequestBody JSONObject paramObject){

        JSONArray channelIdsArray = paramObject.getJSONArray("channelIds");
        if(channelIdsArray == null){
            return AdminResult.failMsg("channelIds 参数缺失").toJsonString();
        }

        List<Long> serverIdList = new ArrayList<>();
        JSONArray serverArray = paramObject.getJSONArray("serverIds");
        if(serverArray != null){
            for (int i = 0; i < serverArray.size(); i++) {
                serverIdList.add(serverArray.getLongValue(i));
            }
        }

        List<Integer> serverStatesArrayList = new ArrayList<>();
        JSONArray serverStatesArray = paramObject.getJSONArray("serverStates");
        if(serverStatesArray != null){
            for (int i = 0; i < serverStatesArray.size(); i++) {
                serverStatesArrayList.add(serverStatesArray.getIntValue(i));
            }
        }

        List<Integer> sererTypeList = new ArrayList<>();
        JSONArray serverTypesArray = paramObject.getJSONArray("serverTypes");
        if(serverTypesArray != null){
            for (int i = 0; i < serverTypesArray.size(); i++) {
                sererTypeList.add(serverTypesArray.getIntValue(i));
            }
        }

        List<String> labelList = new ArrayList<>();
        JSONArray labelNamesArray = paramObject.getJSONArray("labelNames");
        if(labelNamesArray != null){
            for (int i = 0; i < labelNamesArray.size(); i++) {
                labelList.add(labelNamesArray.getString(i));
            }
        }

        int pageNum = paramObject.getIntValue("pageNum");
        int pageSize = paramObject.getIntValue("pageSize");

        long openTimeStart = 0;
        long openTimeEnd = 0;
        if(paramObject.containsKey("openTime")){
            JSONArray time = paramObject.getJSONArray("openTime");
            openTimeStart = DateHelper.str2timestamp(time.getString(0));
            openTimeEnd = DateHelper.str2timestamp(time.getString(1));
        }

        int specialServerParamList = -1;
        if(paramObject.containsKey("specialServerParamList")){
            specialServerParamList = paramObject.getIntValue("specialServerParamList");
        }

        int specialServerType = -1;
        if(paramObject.containsKey("specialServerType")){
            specialServerType = paramObject.getIntValue("specialServerType");
        }


        int channelId = channelIdsArray.getIntValue(0);

        List<ServerInfo> serverList = new ArrayList<>();
        for (ServerInfo serverInfo : ServerListMgr.getChannelServerList(channelId)) {
            //条件筛查
            if(serverIdList.size() > 0 && !serverIdList.contains(serverInfo.getServerId())){
                continue;
            }
            if(serverStatesArrayList.size() > 0 && !serverStatesArrayList.contains(serverInfo.getState())){
                continue;
            }
            if(sererTypeList.size() > 0 && !sererTypeList.contains(serverInfo.getServerType())){
                continue;
            }
            if(labelList.size() > 0 && !labelList.contains(serverInfo.getMarkStr())){
                continue;
            }
            if(openTimeStart > 0 && openTimeEnd > 0){
                if(serverInfo.getOpenTime() < openTimeStart || serverInfo.getOpenTime() > openTimeEnd){
                    continue;
                }
            }
            if(specialServerType > -1 && serverInfo.getSpecialServer() != specialServerType){
                continue;
            }
            if(specialServerParamList > -1 && serverInfo.getSpecialServerParam() != specialServerParamList){
                continue;
            }
            serverList.add(serverInfo);
        }

        AdminResult result = AdminResult.defaultInstance();


        int startIndex = (pageNum - 1) * pageSize;
        startIndex = Math.max(0, startIndex);

        JSONArray data = new JSONArray();

        boolean isChannelOpenSplitFlow = ServerListMgr.isChannelOpenSplitFlow(channelId);

        for (int i = startIndex; i < startIndex + pageSize && i < serverList.size(); i++) {
            JSONObject jsonObject = new JSONObject();
            //
            ServerInfo serverInfo = serverList.get(i);
            jsonObject.put("serverId", serverInfo.getServerId());
            jsonObject.put("serverType", serverInfo.getServerType());
            jsonObject.put("serverName", serverInfo.getServerName());
            //redis
            jsonObject.put("registerNum", RegisterPlayerNumMgr.getRegisterNumByServerId(serverInfo.getServerId()));
            jsonObject.put("createRoleNum", RoleCreateCountMgr.getRoleCreateCountByServerId(serverInfo.getServerId()));
            jsonObject.put("labelName", serverInfo.getMarkStr());

            jsonObject.put("isOpen", serverInfo.isOpen() ? 1 : 0);
            jsonObject.put("serverState", serverInfo.getState() == 1 ? 0 : 1);

            jsonObject.put("openTime", serverInfo.getOpenTime());
            jsonObject.put("channel", serverInfo.getChannelId());

//            jsonObject.put("onlineNum", GamePlayerMgr.getAllOnlinePlayer().size());

            //渠道分流状态
            jsonObject.put("channelSplitStatus", isChannelOpenSplitFlow);

            jsonObject.put("guideQuantityStatus", serverInfo.isOpenSplitFlow());
            jsonObject.put("splitNum", serverInfo.getCreateRoleCountLimit());
            jsonObject.put("openZsDay", serverInfo.getOpenZsDay());
            jsonObject.put("specialServer", serverInfo.getSpecialServer());
            jsonObject.put("createPreRoleNum", serverInfo.getCreatePreRoleNum());

            jsonObject.put("specialServerType", serverInfo.getSpecialServer());

            jsonObject.put("specialServerParam", serverInfo.getSpecialServerParam());

            jsonObject.put("firstOpenServerDate", ServerListMgr.getFirstOpenServerDays(serverInfo));
            jsonObject.put("turn", ServerListMgr.getServerTurn(serverInfo));

            //导量状态
//            jsonObject.put("guideQuantityStatus", serverInfo);
            //轮此
//            jsonObject.put("turn", serverInfo.get);
            //是否新服
//            jsonObject.put("isNew", serverInfo.);
            data.add(jsonObject);
        }

        result.getData().put("total", serverList.size());
        result.getData().put("data", data);
        return result.toJsonString();
    }


    /**
     *  4.4 选择开服/选择维护
     */
    @ResponseBody
    @RequestMapping(value = "serverStateOpt", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String serverStateOpt(HttpServletRequest request, @RequestBody JSONObject paramObject){
        JSONArray serverIds = paramObject.getJSONArray("serverIds");
        if(serverIds == null){
            return AdminResult.failMsg("serverIds 参数缺失").toJsonString();
        }

        if(!paramObject.containsKey("serverState")){
            return AdminResult.failMsg("serverState 参数缺失").toJsonString();
        }

        int state = paramObject.getIntValue("serverState");
        if(state == 1){
            state = 0;
        }else {
            state = 1;
        }

        List<ServerInfo> list = new ArrayList<>();

        for (int i = 0; i < serverIds.size(); i++) {
            long serverId = serverIds.getLongValue(i);
            ServerInfo serverInfo = new ServerInfo();
            serverInfo.setServerId(serverId);
            serverInfo.setState(state);
            list.add(serverInfo);
        }

        boolean b = false;

        if(list.size() > 0){
            b = new AdminCommonDaoImpl().batchUpdateSeverState(list);
        }

        if(!b){
            return AdminResult.failMsg("失败").toJsonString();
        }

        try {
//            new ServerListMgr().reload();
            String message = "ServerListMgr" + ";" + System.currentTimeMillis() / 1000;
            RedisManger.getRedisUtil().publish(eRedisChannelType.CenterManagerReload.getChannel(), eRedisChannelType.CenterManagerReload.getMessageKey(message));
        } catch (Exception e) {
            ServerListMgr.getLogger().info("serverStateOpt 区服加载失败");
        }

        return AdminResult.defaultInstance().toJsonString();
    }


    /**
     *  4.5 刷新服务器配置
     */
    @ResponseBody
    @RequestMapping(value = "refreshServerList", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String refreshServerList(HttpServletRequest request, @RequestBody JSONObject paramObject) {
        JSONArray serverIds = paramObject.getJSONArray("serverList");
        if (serverIds == null) {
            return AdminResult.failMsg("serverList 参数缺失").toJsonString();
        }

        JSONObject object = new JSONObject();

        List<ServerInfo> list = new ArrayList<>();

        for (int i = 0; i < serverIds.size(); i++) {
            Long sid = serverIds.getLong(i);
            ServerInfo serverInfo = ServerListMgr.getServerInfo(sid);
            if(serverInfo == null){
                object.put(String.valueOf(sid), false);
                continue;
            }
            list.add(serverInfo);
        }
        if(list.size() > 0){
            //增加用户中心
//            int i = 101001;
//            String usercenterurl = ConfigHelper.getValue("userCenterPath");
//            if(!StringUtils.isNullOrEmpty(usercenterurl)){
//                List<String> urlList = StringUtils.stringToStringList(usercenterurl, ";");
//                for (String s : urlList) {
//                    ServerInfo serverInfo = new ServerInfo();
//                    serverInfo.setServerId(i++);
//                    serverInfo.setWebServerUrl(s);
//                    list.add(serverInfo);
//                }
//            }

            List<Future> futureList = new ArrayList<>();
            ExecutorService webExecutor = WebServer.getWebExecutor();
            Map<String, String> paramMap = new HashMap<>();
            JSONObject param = new JSONObject();
            param.put("name", "ServerListMgr");
            JSONObject param1 = new JSONObject();
            param1.put("param", param);
            paramMap.put("param", param1.toJSONString());
            for (ServerInfo serverInfo : list) {
                Future future = webExecutor.submit(new Callable<Boolean>() {
                    @Override
                    public Boolean call() throws Exception {
                        String result = "";
                        try {
                            result = HttpHelper.doPost(serverInfo.getWebServerUrl() + "/reloadMgr", paramMap, "UTF-8");
                            JSONObject jsonObject = JSONObject.parseObject(result);
                            if (jsonObject.getIntValue("status") == 1) {
                                object.put(String.valueOf(serverInfo.getServerId()), true);
                            }else {
                                object.put(String.valueOf(serverInfo.getServerId()), false);
                            }
                        } catch (Exception ex) {
                            ServerListMgr.getLogger().error("error, {} {}", result == null ? "" : result, ex.toString());
                        }
                        return true;
                    }
                });
                futureList.add(future);
            }
            if(!futureList.isEmpty()) {
                for (Future future : futureList) {
                    try {
                        boolean ret = (boolean) future.get(12, TimeUnit.SECONDS);
                    } catch (InterruptedException | ExecutionException | TimeoutException e) {
                        e.printStackTrace();
                        ServerListMgr.getLogger().error(" ", e);
                    }
                }
            }
        }

        try {
//            new ServerListMgr().reload();
            String message = "ServerListMgr" + ";" + System.currentTimeMillis() / 1000;
            RedisManger.getRedisUtil().publish(eRedisChannelType.CenterManagerReload.getChannel(), eRedisChannelType.CenterManagerReload.getMessageKey(message));
        } catch (Exception e) {
            ServerListMgr.getLogger().info("serverStateOpt 区服加载失败");
        }

        AdminResult result = AdminResult.defaultInstance();
        result.setData(object);
        return result.toJsonString();
    }


    /**
     *  4.6 区服批量更新
     */
    @ResponseBody
    @RequestMapping(value = "batchUpdateServerInfo", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String batchUpdateServerInfo(HttpServletRequest request, @RequestBody JSONObject paramObject){
        JSONArray serverIds = paramObject.getJSONArray("list");
        if(serverIds == null){
            return AdminResult.failMsg("list 参数缺失").toJsonString();
        }

        List<ServerInfo> list = new ArrayList<>();

        for (int i = 0; i < serverIds.size(); i++) {

            JSONObject object = serverIds.getJSONObject(i);

            ServerInfo serverInfo = new ServerInfo();
            serverInfo.setChannelId(object.getIntValue("channelId"));
            serverInfo.setServerId(object.getLongValue("serverId"));
            serverInfo.setServerName(object.getString("serverName"));
            serverInfo.setMarkStr(object.getString("labelName"));
            serverInfo.setOpen(object.getBoolean("isOpen"));
            serverInfo.setState(object.getIntValue("serverState"));
            serverInfo.setOpenTime(object.getLongValue("openTime") / 1000);
            serverInfo.setOpenSplitFlow(object.getBoolean("isSplit"));
            serverInfo.setCreateRoleCountLimit(object.getIntValue("splitNum"));
            list.add(serverInfo);
        }

        boolean b = false;

        if(list.size() > 0){
            b = new AdminCommonDaoImpl().batchUpdateSeverInfo(list);
        }

        if(!b){
            return AdminResult.failMsg("失败").toJsonString();
        }

        try {
            new ServerListMgr().reload();
        } catch (Exception e) {
            ServerListMgr.getLogger().info("serverStateOpt 区服加载失败");
        }

        return AdminResult.defaultInstance().toJsonString();
    }


    /**
     *  4.7 区服修改
     */
    @ResponseBody
    @RequestMapping(value = "updateServerInfo", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String updateServerInfo(HttpServletRequest request, @RequestBody JSONObject paramObject) {

        ServerInfo serverInfo = new ServerInfo();
        serverInfo.setChannelId(paramObject.getIntValue("channelId"));
        serverInfo.setServerId(paramObject.getLongValue("serverId"));
        serverInfo.setServerName(paramObject.getString("serverName"));
        serverInfo.setServerType(paramObject.getIntValue("serverType"));
        serverInfo.setMarkStr(paramObject.getString("labelName"));
        serverInfo.setOpen(paramObject.getBoolean("isOpen"));
        //状态值要转换
        serverInfo.setState(paramObject.getIntValue("serverState") == 1 ? 0 : 1);
        serverInfo.setOpenTime(paramObject.getLongValue("openTime") / 1000);
        serverInfo.setOpenSplitFlow(paramObject.getBoolean("isSplit"));
        serverInfo.setCreateRoleCountLimit(paramObject.getIntValue("splitNum"));

        int openZsDay = paramObject.getIntValue("openZsDay");
        int specialServer = paramObject.getIntValue("specialServer");
        int createPreRoleNum = paramObject.getIntValue("createPreRoleNum");

        int specialServerParam = paramObject.getIntValue("specialServerParam");
        serverInfo.setSpecialServerParam(specialServerParam);

        serverInfo.setOpenZsDay(openZsDay);
        serverInfo.setSpecialServer(specialServer);
        serverInfo.setCreatePreRoleNum(createPreRoleNum);

        boolean result = new AdminCommonDaoImpl().updateServerInfo(serverInfo);

        if(result){

            try {
                new ServerListMgr().reload();
            } catch (Exception e) {
                ServerListMgr.getLogger().info("serverStateOpt 区服加载失败");
            }

            return AdminResult.defaultInstance().toJsonString();
        }

        return AdminResult.failMsg("失败").toJsonString();
    }

    /**
     *  4.8 读取区服人数
     */
    @ResponseBody
    @RequestMapping(value = "getServerUserCountInfo", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String getServerUserCountInfo(HttpServletRequest request, @RequestBody JSONObject paramObject) {

        JSONArray serverIds = paramObject.getJSONArray("serverIds");
        if(serverIds == null){
            return AdminResult.failMsg("serverIds 参数缺失").toJsonString();
        }
        AdminResult result = AdminResult.defaultInstance();

        for (int i = 0; i < serverIds.size(); i++) {
            long sid = serverIds.getLongValue(i);
            ServerInfo serverInfo = ServerListMgr.getServerInfo(sid);
            if(serverInfo != null && serverInfo.getState() == eServerState.Normal.getValue()){
                String response = HttpHelper.doPost(serverInfo.getWebServerUrl() + "/game/admin/getServerUserCountInfo", null, "UTF-8");
                if(StringUtils.isNullOrEmpty(response)){

                }else {
                    result.getData().put(String.valueOf(sid), JSONObject.parseObject(response));
                }
            }
        }


        return result.toJsonString();
    }

    /**
     *  4.9 特殊服类型下拉框(目前仅大掌柜使用，根据需求对接)
     */
    @ResponseBody
    @RequestMapping(value = "channelsSpecialServerList", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String channelsSpecialServerList(HttpServletRequest request, @RequestBody JSONObject jsonObject){

        AdminResult2 result2 = AdminResult2.defaultInstance();
        List<ServerInfo> serverList = ServerListMgr.getServerList();

        for (ServerInfo serverInfo : serverList) {
            if(serverInfo.getSpecialServer() == 0){
                continue;
            }
            JSONObject serverObj = new JSONObject();
            serverObj.put("specialId", serverInfo.getServerId());
            serverObj.put("specialIdName", serverInfo.getServerName());
            result2.getData().add(serverObj);
        }

        return result2.toJsonString();
    }


    /**
     *  4.10 批量屏蔽/解除屏蔽(目前仅大掌柜使用，根据需求对接)
     */
    @ResponseBody
    @RequestMapping(value = "batchUpdateSpecialServerInfo", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String batchUpdateSpecialServerInfo(HttpServletRequest request, @RequestBody JSONObject paramObject){

        int specialServerParam = paramObject.getIntValue("specialServerParam");

        List<Long> serverIds = new ArrayList<>();

        JSONArray serverIdArray = paramObject.getJSONArray("serverIds");
        for (int i = 0; i < serverIdArray.size(); i++) {
            serverIds.add(serverIdArray.getLongValue(i));
        }

        List<ServerInfo> list = new ArrayList<>();

        for (long serverId : serverIds) {
            ServerInfo serverInfo = new ServerInfo();
            serverInfo.setServerId(serverId);
            serverInfo.setSpecialServerParam(specialServerParam);
            list.add(serverInfo);
        }

        AdminResult result = AdminResult.defaultInstance();
//        boolean b = false;
        AdminCommonDaoImpl dao = new AdminCommonDaoImpl();
        for (ServerInfo info : list) {
            if(dao.updateSpecialSeverInfo(info)){
                result.getData().put(String.valueOf(info.getServerId()), true);
            }else {
                result.getData().put(String.valueOf(info.getServerId()), false);
            }
        }

//        if(list.size() > 0){
//            b = new AdminCommonDaoImpl().batchUpdateSpecialSeverInfo(list);
//        }

//        if(!b){
//            return AdminResult.failMsg("失败").toJsonString();
//        }

        try {
            new ServerListMgr().reload();
        } catch (Exception e) {
            ServerListMgr.getLogger().info("batchUpdateSpecialServerInfo 区服加载失败");
        }


        return result.toJsonString();
    }

    /**
     * 73.1 角色邮件列表
     */
    @ResponseBody
    @RequestMapping(value = "characterMail/Query", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String queryMail(HttpServletRequest request, @RequestBody JSONObject jsonParam){
        if(jsonParam.containsKey("serverId")){
            long serverId = jsonParam.getLongValue("serverId");
            ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
            if(serverInfo != null){
                String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/characterMail/Query", jsonParam.toJSONString(), "UTF-8");
                if(!StringUtils.isNullOrEmpty(response)){
                    return response;
                }
            }
        }

        return AdminResult.failMsg("操作失败").toJsonString();
    }

    /**
     * 73.2 删除角色邮件（涉及扣除角色道具）
     */
    @ResponseBody
    @RequestMapping(value = "characterMail/remove", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String removeMail(HttpServletRequest request, @RequestBody JSONObject jsonParam){
        if(jsonParam.containsKey("serverId")){
            long serverId = jsonParam.getLongValue("serverId");
            ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
            if(serverInfo != null){
                String response = HttpHelper.doPostJson(serverInfo.getWebServerUrl() + "/game/admin/characterMail/remove", jsonParam.toJSONString(), "UTF-8");
                if(!StringUtils.isNullOrEmpty(response)){
                    return response;
                }
            }
        }

        return AdminResult.failMsg("操作失败").toJsonString();
    }

    /**
     * 76.1 公告状态修改、删除公告、内容新增/修改  页签公告管理
     *  1、后台新增/修改公告：多公告内容在新后台维护，传给服务端的公告内容，根据渠道ID/子渠道ID+语言标识判断是否存在，如果不存在就新增，如果存在则是更新；
     *  2、后台禁用公告：实际上是修改公告内容成空字符串。传给服务端公告内容/标题为空字符串，根据渠道ID/子渠道ID+语言标识更新对应公告为空；
     *  3、后台启用公告：则是传需要展示的公告内容，一样根据渠道ID/子渠道ID+语言标识更新对应公告内容；
     *  4、后台删除公告：和禁用公告逻辑相同，传给服务端公告内容/标题为空字符串，根据渠道ID/子渠道ID+语言标识更新对应公告为空；（一般不存在这种情况，后台对每个渠道+子渠道校验至少需要启用一个公告）
     *  5、关于海外无子渠道ID情况，新后台固定会传子渠道ID，服务端需要判断当前渠道是否存在子渠道，决定是否使用子渠道ID更新公告。
     */
    @ResponseBody
    @RequestMapping(value = "channelTabNotice", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public String channelTabNotice(HttpServletRequest request, @RequestBody String json) {
        JSONObject jsObject = JSONObject.parseObject(json);

        int channelId = jsObject.getIntValue("channelId"); // 渠道ID
        String appId = jsObject.getString("appId"); // appId
        JSONArray channelTabNoticeSet = jsObject.getJSONArray("list"); // 页签公告集合数组

        if (eChannelType.forValue(channelId) == null) {
            return AdminResult.failMsg("channelId 错误").toJsonString();
        }

        boolean success = false;

        Map<String, ChannelTabNotice> channelTabNoticeMap = new HashMap<>(); // 按语言划分再入库
        for (int i = 0; i < channelTabNoticeSet.size(); i++) {
            JSONArray channelTabNoticeArr = channelTabNoticeSet.getJSONArray(i); // 页签公告 包含公告多语言
            for (int j = 0; j < channelTabNoticeArr.size(); j++) {
                JSONObject object = channelTabNoticeArr.getJSONObject(j);
                String language = object.getString("language");
                if (!channelTabNoticeMap.containsKey(language)) {
                    ChannelTabNotice channelTabNotice = new ChannelTabNotice();
                    channelTabNotice.setChannelId(channelId);
                    channelTabNotice.setGameType(0);
                    channelTabNotice.setLanguage(language);
                    channelTabNotice.setAppId(appId);
                    channelTabNotice.setTabNotice(new ArrayList<>());
                    channelTabNoticeMap.put(language, channelTabNotice);
                }
                ChannelTabNotice channelTabNotice = channelTabNoticeMap.get(language);
                TabNotice tabNotice = new TabNotice();
                tabNotice.setPictureId(object.getIntValue("pictureId")); // 附图ID
                tabNotice.setContent(object.getString("content")); // 内容
                tabNotice.setTitle(object.getString("title")); // 标题
                tabNotice.setAnnounceTime(object.getString("announceTime")); // 公告时间
                channelTabNotice.getTabNotices().add(tabNotice);
            }
        }

        List<ChannelTabNotice> channelTabNoticeList = new ArrayList<>(channelTabNoticeMap.values());
        if (!channelTabNoticeList.isEmpty()) {
            success = new AdminCommonDaoImpl().batchUpdateChannelTabNotice(channelTabNoticeList);
        }

        if (success) { // 重载
            String message = "ChannelTabNoticeMgr" + ";" + System.currentTimeMillis() / 1000;
            RedisManger.getRedisUtil().publish(eRedisChannelType.CenterManagerReload.getChannel(),
                    eRedisChannelType.CenterManagerReload.getMessageKey(message));
        }

        if (!success) {
            return AdminResult.failMsg("失败").toJsonString();
        }

        return AdminResult.defaultInstance().toJsonString();
    }
}
